package com.sparkseries.common.util.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 响应类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
    /**
     * 响应编码
     */
    private Integer code;
    /**
     * 响应信息
     */
    private String msg;
    /**
     * 响应数据
     */
    private T data;

    /**
     * 失败常量
     */
    public final static Integer FAIL = Constants.DEFAULT_ERROR_CODE ;
    /**
     * 成功常量
     */
    public final static Integer SUCCESS = Constants.DEFAULT_SUCCESS_CODE;

    public static <T> Result<T> ok() {
        return new Result<>(SUCCESS, null, null);
    }
    public static <T> Result<T> ok(String msg) {
        return new Result<>(SUCCESS, msg, null);
    }
    public static <T> Result<T> ok(T data) {
        return new Result<>(SUCCESS, null, data);
    }
    public static <T> Result<T> ok(String msg, T data) {
        return new Result<>(SUCCESS, msg, data);
    }
    public static <T> Result<T> ok(Integer code, String msg) {
        return new Result<>(code, msg, null);
    }
    public static <T> Result<T> ok(Integer code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    public static <T> Result<T> error() {
        return new Result<>(FAIL, null, null);
    }
    public static <T> Result<T> error(String msg) {
        return new Result<>(FAIL, msg, null);
    }
    public static <T> Result<T> error(T data) {
        return new Result<>(FAIL, null, data);
    }
    public static <T> Result<T> error(String msg, T data) {
        return new Result<>(FAIL, msg, data);
    }
    public static <T> Result<T> error(Integer code, String msg) {
        return new Result<>(code, msg, null);
    }
    public static <T> Result<T> error(Integer code, String msg, T data) {
        return new Result<>(code, msg, data);
    }
}
